//
//  BFAuthorAServicces.m
//  BFoodSystem
//
//  Created by 浙江择富 on 2018/1/21.
//  Copyright © 2018年 陈名正. All rights reserved.
//

#import "BFAuthorAServicces.h"
#import "UIImage+LJExtension.h"
@implementation BFAuthorAServicces

+ (void)uploadImagesWithUrl:(NSString *)url  image:(UIImage *)image params:(NSDictionary *)params success:(void (^)(id responseObj))success failure:(void (^)(NSError *error))failure
{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain", nil];

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *urlPath =  url;
    
    [manager POST:urlPath parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSString *indexName = @"file";
        NSData * imageData=UIImageJPEGRepresentation([image fixOrientation:image], 0.8);

        [formData appendPartWithFileData:imageData name:indexName fileName:@"pic.jpg" mimeType:@"image/jpg/file"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if ([resultDic objectForKey:@"code"] == 0) {
            success(resultDic);
        }else{
//            NSInteger code = [[resultDic objectForKey:@"code"] integerValue];
//            NSString *errorMsg = [resultDic objectForKey:@"msg"];
//            errCode(code,errorMsg);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        
    }];
}





@end
